package model

import (
	"gorm.io/gorm"
)

type TsPics struct {
	gorm.Model
	ProductId    uint64 `json:"productId" gorm:"type:bigint(20) unsigned;comment:产品ID"`
	ImagesUrl    string `json:"imagesUrl" gorm:"type:varchar(255);comment:旧图片地址"`
	NewImagesUrl string `json:"newImagesUrl" gorm:"type:varchar(255);comment:新图片地址"`
	Reason       string `json:"reason" gorm:"type:varchar(255);comment:失败原因"`
	IsDeleted    bool   `json:"isDeleted" gorm:"comment:是否已删除下载的文件"`
}

func (s *TsPics) TableName() string {
	return "ts_pics"
}

func (r *TsPics) FirstBytspicIdAndImageUrl(productId uint64, imagesUrl string) (*TsPics, error) {
	var tspic TsPics
	err := GetDB().Where("product_id = ? and images_url = ?", productId, imagesUrl).First(&tspic).Error
	return &tspic, err
}

func (r *TsPics) Create(tspic *TsPics) error {
	return GetDB().Create(tspic).Error
}

func (r *TsPics) Update(tspic *TsPics) error {
	return GetDB().Save(tspic).Error
}
